/**
 * 
 */
package co.gov.medellin.sdep.sisdep.operativa.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.OperDesmonteRet;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IOperDesmonteRetDAOT;
import co.gov.medellin.sdep.sisdep.operativa.exception.OperDesmonteRetException;
import co.gov.medellin.sdep.sisdep.operativa.exception.OperDesmonteRetRuntimeException;
import co.gov.medellin.sdep.sisdep.operativa.exception.descriptor.OperDesmonteRetMessageDescriptor;

/**
 * @author Usuario
 * 
 */
public class OperDesmonteRetServiceImpl extends BaseService implements
		IOperDesmonteRetService {

	// ----------------------------------------------------------------------
	// --- propiedades y constructores init()
	// ----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IOperDesmonteRetDAOT operdesmonteretDAO;

	/**
	 * 
	 */
	public OperDesmonteRetServiceImpl() {
	}

	// ----------------------------------------------------------------------
	// --- propiedades y constructores end()
	// ----------------------------------------------------------------------

	// ----------------------------------------------------------------------
	// --- implementacion de metodos para acciones init()
	// ----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(OperDesmonteRet operdesmonteret)
			throws OperDesmonteRetException {
		try {
			operdesmonteret.setUsuarioCrea(getPrincipalUser());
			// operdesmonteret.setFechaCrea(new Date());
			getOperdesmonteretDAO().insert(operdesmonteret);
		} catch (Exception e) {
			Object[] infoError = { operdesmonteret.getCodigo() };
			if (e.getCause().toString().indexOf("UNIQUE KEY") >= 0) {
				throw new OperDesmonteRetException(
						new OperDesmonteRetMessageDescriptor(
								MessageDescriptorConstant.UK_VIOLATION),
						infoError, e);
			} else {
				throw new OperDesmonteRetException(
						new OperDesmonteRetMessageDescriptor(
								MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(OperDesmonteRet operdesmonteret)
			throws OperDesmonteRetException {
		try {
			operdesmonteret.setUsuarioModifica(getPrincipalUser());
//			operdesmonteret.setFechaModifica(new Date());
			getOperdesmonteretDAO().update(operdesmonteret);
		} catch (Exception e) {
			Object[] infoError = { operdesmonteret.getCodigo() };
			if (e.getCause().toString().indexOf("UNIQUE KEY") >= 0) {
				throw new OperDesmonteRetRuntimeException(
						new OperDesmonteRetMessageDescriptor(
								MessageDescriptorConstant.UK_VIOLATION),
						infoError, e);
			} else {
				throw new OperDesmonteRetRuntimeException(
						new OperDesmonteRetMessageDescriptor(
								MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(OperDesmonteRet operdesmonteret)
			throws OperDesmonteRetException {
		try {
			operdesmonteret.setUsuarioModifica(getPrincipalUser());
//			operdesmonteret.setFechaModifica(new Date());
			getOperdesmonteretDAO().delete(operdesmonteret);
		} catch (Exception e) {
			Object[] infoError = { operdesmonteret.getCodigo() };
			throw new OperDesmonteRetRuntimeException(
					new OperDesmonteRetMessageDescriptor(
							MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return
	 * 
	 */
	public final List load(int start, int max, OperDesmonteRet operdesmonteret)
			throws OperDesmonteRetException {
		try {
			// return
			// getOperDesmonteRetDAO().getAllOperDesmonteRetPaginated(start,
			// max, criteria);
			return getOperdesmonteretDAO().load(
					operdesmonteret);
		} catch (Exception e) {
			Object[] infoError = null;
			throw new OperDesmonteRetRuntimeException(
					new OperDesmonteRetMessageDescriptor(
							MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final OperDesmonteRet get(long id) throws OperDesmonteRetException {
		try {
			return getOperdesmonteretDAO().findByPrimaryKey(id);
		} catch (Exception e) {
			Object[] infoError = { new Long(id) };
			throw new OperDesmonteRetRuntimeException(
					new OperDesmonteRetMessageDescriptor(
							MessageDescriptorConstant.GET), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final List searchByParametersDinamycally(OperDesmonteRet criteria)
			throws OperDesmonteRetException {
		try{
		return getOperdesmonteretDAO().searchByParametersDinamycally(
				criteria);
	} catch (Exception e) {
		Object[] infoError = null;
		throw new OperDesmonteRetRuntimeException(
				new OperDesmonteRetMessageDescriptor(
						MessageDescriptorConstant.RETRIEVE), infoError, e);
	}
	}

	// ----------------------------------------------------------------------
	// --- implementacion de metodos para acciones end()
	// ----------------------------------------------------------------------

	// ----------------------------------------------------------------------
	// --- getters and setters init()
	// ----------------------------------------------------------------------

	/**
	 * @return the operdesmonteretDAO
	 */
	public IOperDesmonteRetDAOT getOperdesmonteretDAO() {
		return operdesmonteretDAO;
	}

	/**
	 * @param operdesmonteretDAO
	 *            the operdesmonteretDAO to set
	 */
	public void setOperdesmonteretDAO(IOperDesmonteRetDAOT operdesmonteretDAO) {
		this.operdesmonteretDAO = operdesmonteretDAO;
	}

	// ----------------------------------------------------------------------
	// --- getters and setters end()
	// ----------------------------------------------------------------------

}
